package com.atguigu.flink.chapter05.Transform;

import com.atguigu.flink.bean.WaterSensor;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/8/9 10:30
 */
public class Flink06_Shuffle {
    public static void main(String[] args) throws Exception {
        // 0.执行环境
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());

        // 1.读取数据
        //  sensor_1,123123213,10
        DataStreamSource<String> socketDS = env.socketTextStream("localhost", 9999);

        socketDS.print("input>>>>>");
        socketDS.shuffle().print("shuffle>>>>");

        env.execute();
    }
}

/*
    shuffle: 数据重新分区
        随机的，分区器的逻辑：  random.nextInt(并行度)

    应用场景： 数据来源本身就不均匀，避免将倾斜压力传递给下游算子，先shuffle打散
 */
